package com.cenntro.oss.controller;


import java.util.List;

import javax.annotation.Resource;

import org.apache.curator.shaded.com.google.common.collect.ImmutableMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cenntro.common.base.BaseController;
import com.cenntro.common.model.dbo.SysconfDO;
import com.cenntro.common.util.ConvertorUtils;
import com.cenntro.common.util.result.PageResult;
import com.cenntro.common.util.result.Result;
import com.cenntro.oss.model.dbo.SysAgentDO;
import com.cenntro.oss.model.vo.SysConfVO;
import com.cenntro.oss.service.SysConfService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
* @ClassName: SysConfController
* @Description:前端控制器，数据字典
* @author 15815
* @date 2019年7月3日
*
 */
@Api(value="字典管理", tags={"字典管理"})
@RestController
@RequestMapping("/conf")
public class SysConfController extends BaseController {

	
	@Resource
	private SysConfService sysConfService;
	
	/**
	 * 
	* @Title selectPage
	* @Description 数据字典查询信息列表
	* @param 
	* @return  
	* @throws
	 */
	@ApiOperation(value="数据字典查询")
	@CrossOrigin
	@RequestMapping("/selectPage")
	public Result selectPage(SysConfVO sysconf){
		SysconfDO conf = ConvertorUtils.deepConvert(sysconf, SysconfDO.class);
		conf.setStatus(1);
		Page<SysAgentDO> page = PageHelper.startPage(sysconf.getPage(), sysconf.getLimit(), true);
		List<SysconfDO> list = sysConfService.selectPage(conf);
		
		return PageResult.ok(list, page.getTotal());
	}
	
	@ApiOperation(value="数据字典查询")
	@CrossOrigin
	@RequestMapping("/code")
	public Result code( String code){
		List<SysconfDO> list = sysConfService.selectPage(ImmutableMap.of("code",code));
		
		return PageResult.ok(list);
	}
	
}
